local DIY = require "packages/diy_utility/diy_utility"

local skels={}
local jielin = fk.CreateSkill{
  name = "steam__jielin",
  tags = { DIY.ReadySkill},
}

Fk:loadTranslationTable{
  ["steam__jielin"] = "揭鳞",
  [":steam__jielin"] = "蓄势技，【杀】进入弃牌堆的回合结束后，你可视为使用放弃发动本技能次数张火【杀】，横置因之濒死角色，获得杀死角色于此位置的额定回合。",
  ["#steam__jielin-invoke"] = "揭鳞：你可视为使用%arg张火【杀】",
  ["#steam__jielin-target"] = "揭鳞：请选择目标",
  ["@steam__jielin"] = "揭鳞",
  ["@steam__jieli_getturn"] = "揭鳞回合",
}

jielin:addEffect(fk.TurnEnd,{
  mute = true,
  can_trigger = function (self, event, target, player, data)
      if player:hasSkill(jielin.name) then
          local room = player.room
          local ids = {}
          room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
              for _, move in ipairs(e.data) do
                  if move.toArea == Card.DiscardPile then
                      for _, info in ipairs(move.moveInfo) do
                          if Fk:getCardById(info.cardId, true).trueName == "slash" then
                              table.insertIfNeed(ids, info.cardId)
                          end
                      end
                  end
              end
          end, Player.HistoryTurn)
          return #ids > 0
      end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local n=player:getMark("@steam__jielin")
    if room:askToSkillInvoke(player,{
      skill_name = jielin.name,
      prompt = "#steam__jielin-invoke:::"..n,
    }) then
      event:setCostData(self,{number = number})
      return true
    else
      room:addPlayerMark(player,"@steam__jielin")
    end
  end,
  on_use = function (self, event, target, player, data)
      local room = player.room
      local n=player:getMark("@steam__jielin")
      for i = 1, n, 1 do
        if player.dead then return end
        room:askToUseVirtualCard(player, {
          name= "fire__slash",
          skill_name=jielin.name,
        })
      end
      room:setPlayerMark(player,"@steam__jielin",0)
  end,
})

jielin:addEffect(fk.AfterDying, {
  mute = true,
  can_refresh = function (self, event, target, player, data)
   if player:hasSkill(jielin.name) and data.damage and data.damage.card then
    return data.damage.card.skillName==jielin.name
   end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if not target.dead then
      target:setChainState(true)
    else
      room:addTableMarkIfNeed(player, "@steam__jieli_getturn", target.seat)
    end
  end,
})

jielin:addEffect(fk.EventTurnChanging, {
  can_refresh = function (self, event, target, player, data)
    return table.contains(player:getTableMark("@steam__jieli_getturn"), data.to.seat)
  end,
  on_refresh = function (self, event, target, player, data)
    data.to = player
  end,
})
return jielin 